package br.atribicoes.professor

import br.academia.Professor

class CapacitacaoDocenteController {

	def scaffold = CapacitacaoDocente

	def save = {

		def capacitacaoDocenteInstance = new CapacitacaoDocente(params)

		Professor professor = Professor.findByUsername(session.user)

		println ("Professor "+professor)

		if (professor){
			if (capacitacaoDocenteInstance.save(flush: true)){
				professor.addToCapacitacaoDocente(capacitacaoDocenteInstance)
				flash.message = "${message(code: 'default.created.message', args: [message(code: 'capacitacaoDocente.label', default: 'Capacitacao Docente'), capacitacaoDocenteInstance.id])}"
				redirect(action: "show", id: capacitacaoDocenteInstance.id)
			}else{
				flash.message = "ERRO!"
				render(view: "create", model: [capacitacaoDocenteInstance: capacitacaoDocenteInstance])
				return
			}
		}
		else{
			flash.message = "Professor Invalido no Sistema!"
			render(view: "create", model: [capacitacaoDocenteInstance: capacitacaoDocenteInstance])
			return
		}
	}
}
